<!--忘记密码页面  -->
<template>
  <div class="register-card">
    <h3 class="register-title">Forget password</h3>
    <p class="register-desc">Hello, welcome to COVID-19 Vaccine fund</p>
    <div class="register-form">
      <div class="form-item">
        <input
          type="password"
          v-model="loginForm.password"
          placeholder="Password"
        />
      </div>
      <div class="form-item">
        <input
          type="password"
          v-model="loginForm.againpassword"
          placeholder="Repeat the password"
        />
      </div>
      <div class="form-item">
        <input
          type="text"
          v-model="loginForm.phone"
          placeholder="Phone number"
        />
      </div>
      <div class="user-name">
        <div class="text">
          <input
            type="tel"
            v-model="loginForm.verification_code"
            placeholder="Verification Code"
          />
        </div>
        <div class="send" @click="setCodeEvent">{{ $t("senout") }}</div>
      </div>

      <button @click="determine">
        <img src="../../assets/imgs/changeLoginPassword_4.png" alt="" />Submit
      </button>
    </div>
  </div>
</template>

<script>
import { countDwon } from "@/utils/common";
import { Toast } from "vant";
export default {
  data() {
    return {
      loginForm: {
        password: "",
        againpassword: "",
        phone: "",
        verification_code: "",
        verification_key: "",
      },
    };
  },
  methods: {
    determine() {
      if (!this.loginForm.verification_code) {
        Toast("Please enter the verification code");
        return;
      }
      if (this.loginForm.password !== this.loginForm.againpassword) {
        Toast("The two passwords do not match");
        return;
      }
      this.$store
        .dispatch("forget", {
          verification_key: this.loginForm.verification_key,
          verification_code: this.loginForm.verification_code,
          password: this.loginForm.password,
        })
        .then((result) => {
          Toast("Password changed successfully");
          this.$router.back();
          this.loginForm = {};
        });
    },
    // 获取验证码
    setCodeEvent(e) {
      if (this.loginForm["phone"] != "") {
        this.$store
          .dispatch("sendcode", {
            phone: this.loginForm.phone,
            area: 91,
            type: "register",
            captcha_key: "1",
            captcha_code: this.invatecode,
          })
          .then((result) => {
            countDwon(e.target, 60);
            this.loginForm.verification_key = result;
            Toast(this.$i18n.tc("sendsuccess"));
          });
      } else {
        this.$toast(this.$i18n.tc("pelasephone"));
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.register-card {
  height: 100%;
  min-height: 100vh;
  padding: 0 38px;
  background: url("../../assets/imgs/register_bg.png");
  background-size: contain;
  .register-title {
    padding: 70px 0 0 0;
    font-weight: bold;
    font-size: 35px;
    line-height: 35px;
  }
  .register-desc {
    margin: 12px 0 0 0;
    font-size: 12px;
  }
  .register-form {
    margin: 43px 0 0 0;
    font-size: 15px;
    color: #fff;
    .form-item {
      margin: 0 0 10px 0;
      input {
        box-sizing: border-box;
        width: 300px;
        height: 50px;
        border: none;
        background: #f7f7f8;
        color: #adb4c7;
        font-size: 15px;
        padding: 0 10px;
        border-radius: 5px;
      }
    }
    .form-item-fff {
      margin: 0 0 10px 0;
      input {
        width: 300px;
        height: 50px;
        border: none;
        color: #adb4c7;
        font-size: 15px;
        padding: 0 10px;
        border-radius: 5px;
      }
    }
    .form-item p {
      margin: 0 0 12px 0;
    }

    input::-webkit-input-placeholder {
      color: #adb4c7;
    }
    button {
      margin: 20px 0 0 0;
      width: 300px;
      height: 50px;
      line-height: 50px;
      background: #4a67f5;
      box-shadow: 0px 2px 6px rgba(45, 88, 234, 0.5);
      opacity: 1;
      border-radius: 25px;
      display: flex;
      align-items: center;
      justify-content: center;
      border: none;
      > img {
        width: 15px;
        height: 15px;
        margin-right: 5px;
      }
    }
  }
  .user-name {
    width: 300px;
    height: 50px;
    border-radius: 5px;
    background: #f7f7f8;
    margin: 0 0 10px 0;

    display: flex;
    align-items: center;
    .text {
      flex: 1;
      display: flex;
      input {
        font-size: 15px;
        padding: 0 10px;
        height: 50px;
        flex: 1;
        border: none;
        background: #f7f7f8;
      }
    }
    .send {
      width: 64px;
      margin: 0 10px 0 0;
      height: 26px;
      font-size: 12px;
      color: #4c6cf1;
      padding: 2px 8px;
      background: #e3e7fe;
      border: 1px solid #4c6cf1;
      opacity: 1;
      border-radius: 20px;
      text-align: center;
      line-height: 26px;
    }
  }
  .forget-pass {
    text-align: center;
    margin: 62px 0 0 0;
    font-size: 15px;
    color: #4a67f5;
  }
  .to-sign {
    margin: 96px 0 0 0;
    text-align: center;
    color: #fff;
    span {
      font-size: 15px;
      color: #2c57e7;
    }
  }
}
</style>